import network from '../../utils/network.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
      id:'',
      name:'',
      address:'', 
      isHiddenToast: true,
      page: 1,
      rows: 5,
      total: 0,
      hasMoreData: true,
      Inx: 0,
      list: [],
      userInfo:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var id = options.id;
    that.setData({
      id:id,
    });
    that.onGetDetail('正在加载中');
  },

  onGetDetail:function (message){
    var that = this;
    var data = {id:that.data.id};
    network.requestLoading('http://jbc.com/api/Member/shop_detail', data, message, function (res) {
     
      if (res.code > 0) { 
          that.setData({
            name:res.data.name, 
            address: res.data.province + res.data.city + res.data.district + res.data.detail,
          }); 
        that.onGetCarList("加载车型列表");
      } else {
        // wx.showToast({
        //   title: res.msg,
        // });
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    }) 
  },


  onGetCarList: function (message) {
    var that = this;
    var data = {
      id: that.data.id, 
      rows: that.data.rows,
      page: that.data.page, };
    network.requestLoading('http://jbc.com/api/Member/shop_car_list', data, message, function (res) {
      var contentlistTem = that.data.list;
      if (res.code > 0) {
        if (contentlistTem.length < res.data.total) {
          that.setData({
            page: that.data.page + 1,
            list: res.data.list,
          });
        } else {
          that.setData({
            hasMoreData: false
          });
        }
      } else {
        // wx.showToast({
        //   title: res.msg,
        // });
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    })
  },
  /**
   * 关注店铺
   */
  onGuanz:function(e){
   var that = this;
   var user_id = '';
    wx.getLocation({
      type: 'wgs84',
      success: function (re) {
        console.log(re);
        var data = { id: that.id, member_id: re.data.id };
        network.requestLoading('http://jbc.com/api/Member/shop_follow', data, "等待执行操作", function (res) {
          if (res.code > 0) {
            wx.showToast({
              title: res.msg,
            });
          } else {
            wx.showToast({
              title: res.msg,
            });
          }
        }, function (res) {
          wx.showToast({
            title: '加载数据失败',
          })
        }); 
      }
    });
    
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
* 页面相关事件处理函数--监听用户下拉动作
*/
  onPullDownRefresh: function () {
    this.data.page = 1;
    this.onGetShopList('正在刷新数据')
    console.log("下拉加载更多")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("下滑加载更多")
    if (this.data.hasMoreData) {
      this.onGetShopList('加载更多数据');
    } else {
      console.log("没有更多的数据")
      wx.showToast({
        title: '没有更多数据',
      })
    }
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})